package com.hjx.other;

import java.util.ArrayList;
import java.util.List;

public class IncomeFax {

    public static void main(String[] args) {
        // 小王每月工资两万，浮动奖金为0，专项扣除费为1500，上海的五险一金比例为17.5%
        System.out.println(getMonthlySal(25000, new double[12], 1000.0, 0.2153));
        System.out.println(getMonthlySal(28000, new double[12], 1000.0, 0.2153));
        System.out.println(getMonthlySal(32000, new double[12], 1000.0, 0.2153));
        System.out.println(getMonthlySal(35000, new double[12], 1000.0, 0.2153));
        System.out.println(getMonthlySal(46410, new double[12], 5000.0, 0.126));
    }

    /**
     * @param defaultSal 基本工资
     * @param bonus      浮动奖金（绩效工资）一年内拿了几次工资就输入几个
     * @param special    专项扣除
     * @param insurance  五险一金比例
     */
    public static List<Double> getMonthlySal(double defaultSal, double[] bonus, double special, double insurance) {
        // 累计预扣缴额
        double totalNeedTax = 0.0;
        // 累计已缴税额
        double totalHadTax = 0.0;
        // 每月工资
        List<Double> salArr = new ArrayList<>();
        for (double b : bonus) {
            // 当月预扣缴额(每月的应缴税 = 基本工资 + 浮动奖金(绩效工资) - 起征点 - 专项扣除 - 五险一金)
            double shouldTax = defaultSal + b - 5000 - special - defaultSal * insurance;
            totalNeedTax += shouldTax;
            // 累计应缴税额(累计应缴税额 * 税率 - 速算扣除数`)
            double totalTax;
            if (totalNeedTax <= 36000.0) {
                totalTax = totalNeedTax * 0.03;
            } else if (totalNeedTax <= 144000.0) {
                totalTax = totalNeedTax * 0.1 - 2520;
            } else if (totalNeedTax <= 300000.0) {
                totalTax = totalNeedTax * 0.2 - 16920;
            } else if (totalNeedTax <= 420000.0) {
                totalTax = totalNeedTax * 0.25 - 31920;
            } else if (totalNeedTax <= 660000.0) {
                totalTax = totalNeedTax * 0.30 - 52920;
            } else if (totalNeedTax <= 960000.0) {
                totalTax = totalNeedTax * 0.35 - 85920;
            } else {
                totalTax = totalNeedTax * 0.45 - 181920;
            }
            // 当月应缴税(当月累计应缴税 - 上月累计应缴税(累计已缴税))
            double curTax = totalTax - totalHadTax;
            // 当月工资(当月工资 = 基本工资 + 浮动奖金(绩效工资) - 当月应缴税 - 五险一金)
            double curSal = defaultSal + b - curTax - defaultSal * insurance;
            salArr.add(curSal);
            totalHadTax = totalTax;
        }
        return salArr;
    }
}